#include "light.h"

OLight::OLight(QObject *parent) :
    BasicObject(parent)
{
    m_xPos = m_yPos = m_zPos = 0;
    m_specRed = m_specGreen = m_specBlue = 0.1;
    m_DifRed = m_DifGreen = m_DifBlue = 0.1;
    m_dirZ = m_dirX = m_dirY = 0;
    m_light = 0;
    m_nodeId = "";
}

void OLight::updatePos()
{
    if (m_light == 0) return;
    m_light->setPosition(m_xPos, m_yPos, m_zPos);
}

float OLight::xPos() const {
    return m_xPos;
}

void OLight::setXPos(float pos) {
    this->m_xPos = pos;
        updatePos();
}

float OLight::yPos() const {
    return m_yPos;
}

void OLight::setYPos(float pos) {
    this->m_yPos = pos;
        updatePos();
}

float OLight::zPos() const {
    return m_zPos;
}

void OLight::setZPos(float pos) {
    this->m_zPos = pos;
        updatePos();
}

void OLight::setDifRed(float c) {
    m_DifRed = c;
    if (m_light == 0) return;
    m_light->setDiffuseColour(Ogre::ColourValue(m_DifRed, m_DifGreen, m_DifBlue));
}

void OLight::setDifGreen(float c) {
    m_DifGreen = c;
    if (m_light == 0) return;
    m_light->setDiffuseColour(Ogre::ColourValue(m_DifRed, m_DifGreen, m_DifBlue));
}

void OLight::setDifBlue(float c) {
    m_DifBlue = c;
    if (m_light == 0) return;
    m_light->setDiffuseColour(Ogre::ColourValue(m_DifRed, m_DifGreen, m_DifBlue));
}

void OLight::setSpecRed(float c) {
    m_specRed = c;
    if (m_light == 0) return;
    m_light->setSpecularColour(Ogre::ColourValue(m_specRed, m_specGreen, m_specBlue));
}

void OLight::setSpecGreen(float c) {
    m_specGreen = c;
    if (m_light == 0) return;
    m_light->setSpecularColour(Ogre::ColourValue(m_specRed, m_specGreen, m_specBlue));
}

void OLight::setSpecBlue(float c) {
    m_specBlue = c;
    if (m_light == 0) return;
    m_light->setSpecularColour(Ogre::ColourValue(m_specRed, m_specGreen, m_specBlue));
}

float OLight::dirZ() const
{
    return m_dirZ;
}

float OLight::dirX() const
{
    return m_dirX;
}

float OLight::dirY() const
{
    return m_dirY;
}

void OLight::setDirZ(float scale)
{
    m_dirZ = scale;
    updateDir();
}

void OLight::setDirY(float scale)
{
    m_dirY = scale;
    updateDir();
}

void OLight::setDirX(float scale)
{
    m_dirX = scale;
    updateDir();
}

void OLight::updateDir()
{
    if (m_light == 0) return;
    m_light->setDirection(m_dirX, m_dirY, m_dirZ);
}
